import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;


public class Ex1_clump {
	
	/*
	 * Main method
	 */
	public static void main(String[] args) {		
		
		System.out.println(new Date());
		
		try {
			// input parameters
			int k = 9;
			int l = 500;
			// int t = 3;						
			String genome = KmerCounter.readFile("C:\\Users\\josemfer\\Downloads\\E-coli.txt").trim();		
			
			// internal vars
			//ArrayList<String> kmers = new ArrayList<String>();		
			HashMap<String,ArrayList<Integer>> hm = 
								new HashMap<String,ArrayList<Integer>>();
			HashMap<String,ArrayList<Integer>> hmk = 
					new HashMap<String,ArrayList<Integer>>();
			ArrayList<Integer> klist;
			
			// get k-mers (with indexes array)		
			for (int i=0;i < genome.length() - k  ; i++) {
				String km = genome.substring(i,i+k);
				if (!hm.containsKey(km)    ) { // if no contains key...
					klist = new ArrayList<Integer>();
					klist.add(i);					
					hm.put(km,klist);				
				} else {	// if contains key
					klist = hm.get(km);
					if (klist.size() == 1 ) {
						if ( i - klist.get(0)  < l - 2*k  ) {
							klist.add(i);	// two elements in index list						
						} else {
							klist.set(0, i);
						}
					} else if (klist.size() == 2 ) {
						if (  i - klist.get(0) < (l - k)  ) {
							klist.add(i);// three elements!
							hmk.put(km, klist);
						} else {
							klist.remove(0);
							klist.add(i);
						}
					}					
				}
			}			
			
			// remove kmers for non repeating t times
			/*
			for (String km : hm.keySet()) {
				ArrayList<Integer> ai = hm.get(km);
				if (ai.size() >= t) {					
					// iterate over positions of kmer
					for (int i=0; i< ai.size() - t +1;i++) {	
						int lon = ai.get(i + t - 1) - ai.get(i);
						if (lon <= l - k) {
							ArrayList<Integer> al = new ArrayList<Integer>();
							al.add(lon);
							hmk.put(km, al);	
							break;
						}							
					}					
				}
			}
				*/			
			
			System.out.println(hmk.size());
			System.out.println(new Date());
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}			
	} // main	
}
